package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;
	@Resource
	private VodService vodService;


	@PostMapping("uploadTrack")
	public Result uploadTrack(MultipartFile file){
		Object obj=vodService.uploadTrack(file);
		return Result.ok(obj);
	}

	@GuiGuLogin
	@PostMapping("saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}

	@GuiGuLogin
	@PostMapping("findUserTrackPage/{page}/{limit}")
	public Result findUserTrackPage(@RequestBody TrackInfoQuery trackInfoQuery,
									@PathVariable Integer page,
									@PathVariable Integer limit){
		Page<TrackListVo> trackListVoPage=trackInfoService.findUserTrackPage(page,limit,trackInfoQuery);
		return Result.ok(trackListVoPage);
	}

	@GetMapping("getTrackInfo/{trackId}")
	public Result getTrackInfo(@PathVariable Long trackId){
		TrackInfo trackInfo=trackInfoService.getById(trackId);
		return Result.ok(trackInfo);
	}

	@GuiGuLogin
	@PutMapping("updateTrackInfo/{trackId}")
	public Result updateTrackInfo(@PathVariable Long trackId,
								  @RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.updateTrackInfo(trackId,trackInfoVo);
		return Result.ok();
	}

	@GuiGuLogin
	@DeleteMapping("removeTrackInfo/{trackId}")
	public Result removeTrackInfo(@PathVariable Long trackId){
		trackInfoService.removeTrackInfo(trackId);
		return Result.ok();
	}
	@GuiGuLogin(required = false)
	@GetMapping("findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<Page<AlbumTrackListVo>> findAlbumTrackPage(@PathVariable Long albumId,
															 @PathVariable Integer page,
															 @PathVariable Integer limit){
		Page<AlbumTrackListVo> albumTrackListVoPage = trackInfoService.findAlbumTrackPage(albumId,page,limit);
		return Result.ok(albumTrackListVoPage);
	}


}

